/**
 *====================================================
 * 文件名称: AbnormalSurveyServiceImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年11月21日	chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.common.util.BeanUtils;
import com.yuexunit.finance.project.entity.AbnormalSurveyEntity;
import com.yuexunit.finance.project.entity.lexicon.AuthenticatStateEnum;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.util.DateUtil;

/**
 * @ClassName: AbnormalSurveyServiceImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenxy
 * @date 2015年11月21日 13:42:35
 */
@Implements(AbnormalSurveyService.class)
public class AbnormalSurveyServiceImpl implements AbnormalSurveyService {

	@Override
	public Long createAbnormalSurvey(AbnormalSurveyEntity entity) {
		entity.setAuthenticatState(AuthenticatStateEnum.UNCONFIRM);
		entity.setCreateDateTime(DateUtil.now());
		PersistUtil.insert(entity);
		return entity.getAbnormalSurveyId();
	}

	@Override
	public void updateAbnormalSurvey(AbnormalSurveyEntity entity) {
		AbnormalSurveyEntity persist = inquireAbnormalSurvey(entity.getAbnormalSurveyId());
		BeanUtils.copyProperties(entity, persist);
		PersistUtil.update(persist);
	}

	@Override
	public void renovateAbnormalSurvey(AbnormalSurveyEntity persist) {
		PersistUtil.update(persist);
	}

	@Override
	public AbnormalSurveyEntity inquireAbnormalSurvey(Long abnormalSurveyId) {
		return PersistUtil.get(AbnormalSurveyEntity.class, abnormalSurveyId);
	}

	@Override
	public List<AbnormalSurveyEntity> inquireAbnormalSurveyList(Long abnormalId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(AbnormalSurveyEntity.class);
		criteria.add(Restrictions.eq("abnormalId", abnormalId));
		return PersistUtil.get(criteria);
	}

	@Override
	public PageList<AbnormalSurveyEntity> inquireAbnormalSurveyPageList(Long abnormalId, PageCriteria page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(AbnormalSurveyEntity.class);
		criteria.add(Restrictions.eq("abnormalId", abnormalId));
		return PersistUtil.get(criteria, page);
	}

}
